package cn.edu.tsc.dao;

import cn.edu.tsc.pojo.Emp;

import java.util.List;

public class EmpDao {

    public List<Emp> FindAll() {
        String sql = "select id,name,depart,salary from t_emp";
        List<Emp> emps = common.getForList(Emp.class, sql);
        return emps;
    }


    public int deletEmpById(int id) {
        String sql = "delete from t_emp where id = ?";
        int flag = common.update(sql, id);
        return flag;
    }

    public int addEmp(Emp emp) {
        String sql = "INSERT INTO t_emp VALUES(?,?,?,?);";
        int flag = common.update(sql, emp.getId(), emp.getName(), emp.getDepart(), emp.getSalary());
        return flag;
    }


    public int updateEmp(Emp emp) {
        String sql = "UPDATE  t_emp SET  NAME = ?,depart= ? ,salary=? WHERE  id =?;";
        int flag = common.update(sql, emp.getName(), emp.getDepart(), emp.getSalary(), emp.getId());
        return flag;
    }

    public Emp selById(int id) {
        String sql = "select id,name,depart,salary from t_emp where id = ?";
        Emp emp = common.getInstance(Emp.class, sql, id);
        return emp;
    }

    public List<Emp> search(String search) {
        String sql = "select id,name,depart,salary from t_emp where name like ?;";
        List<Emp> emps = common.getForList(Emp.class, sql, "%"+search+"%");
        return emps;
    }
}
